enum NUMS {
    //% block="不限"
    0,
    //% block="30"
    30,
    //% block="50"
    50,
    //% block="100"
    100,
}


//% color="#ef784c" iconWidth=50 iconHeight=40
namespace Unihiker_XunFei_Platform{

    //% block="火星认知模型初始化，APP_ID[APP_ID], APP_KEY[APP_KEY],APP_SECRET[APP_SECRET], LLM_DOMAIN[LLM_DOMAIN]" blockType="command"
    //% APP_ID.shadow="string" APP_ID.defl="5572ead9"
    //% APP_KEY.shadow="string" APP_KEY.defl="9cb9c6be55d8f1750aea2af6c448f402"
    //% APP_SECRET.shadow="string" APP_SECRET.defl="NmQ0ZWIyNTQ2ZjA3Y2Q0NGUxNWQ5YTk0"
    //% LLM_DOMAIN.shadow="string" LLM_DOMAIN.defl="generalv3.5"
    export function xunfei_init(parameter: any, block: any) {
        let app_id=parameter.APP_ID.code;
        let app_key=parameter.APP_KEY.code;
        let app_secret=parameter.APP_SECRET.code;
        let app_domain=parameter.LLM_DOMAIN.code;
        Generator.addCode(`XF_APP_ID=${app_id}`);
        Generator.addCode(`XF_APP_KEY=${app_key}`);
        Generator.addCode(`XF_APP_SECRET=${app_secret}`);
        Generator.addCode(`XF_LLM_DOMAIN=${app_domain}`)
    }

    //% block="回答[NAME], 内容限制在[LENGTH]字以内" blockType="reporter"
    //% NAME.shadow="string" NAME.defl="喝茶有什么好处？"
    //% LENGTH.shadow="dropdown" LENGTH.options="NUMS" LENGTH.defl="NUMS.A"
    export function get_xunfei_answer(parameter: any, block: any) {
        let name=parameter.NAME.code;
        let length=parameter.LENGTH.code;
        Generator.addImport(`from xunfei_chat_api import get_xunfei_chat`);
        Generator.addCode(`get_xunfei_chat(${name}, ${length}, XF_APP_ID, XF_APP_KEY, XF_APP_SECRET, XF_LLM_DOMAIN)`)
    }

    //% block="根据问题[NAME]生成图片[FILEPATH]" blockType="command"
    //% NAME.shadow="string" NAME.defl="阳光照耀下的龙井茶园"
    //% FILEPATH.shadow="string" FILEPATH.defl="img.png"
    export function get_xunfei_image(parameter: any, block: any) {
        let name=parameter.NAME.code;
        let filepath=parameter.FILEPATH.code;
        Generator.addImport(`from word2picture import xunfei_to_image`)
        Generator.addCode(`xunfei_to_image(${name}, ${filepath}, XF_APP_ID, XF_APP_KEY, XF_APP_SECRET)`)
        //Generator.addImport(`from xunfei_chat_api import get_xunfei_image`)
        //Generator.addCode(`get_xunfei_image(${name}, ${filepath}, XF_APP_ID, XF_APP_KEY, XF_APP_SECRET)`)
    }

    //% block="根据录音[FILENAME]转文字" blockType="reporter"
    //% FILENAME.shadow="string" FILEPATH.defl="record.wav"
    export function voice_to_words(parameter: any, block: any) {
        let filename=parameter.FILENAME.code;
        Generator.addImport(`from xunfei_chat_api import voice_to_words`)
        Generator.addCode(`voice_to_words(file=${filename})`)
    }

}
